<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test_weibo_api extends CI_Controller {

	/**
	* __construct 
	*
	* @access public
	* @return string $mixed
	*/
	public function __construct() {
        parent::__construct();
	}

    function send_http($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 25);
        curl_setopt($ch,CURLOPT_POST,true);
        curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query(array(
            'urls' => array(
                'http://weibo.com/1640571365/CbysddXVO?from=page_1035051640571365_profile&wvr=6&mod=weibotime&type=comment',
                'http://weibo.com/1640571365/CbfpG8SHs?from=page_1035051640571365_profile&wvr=6&mod=weibotime',
            ),
        )));

        $rs = curl_exec($ch);
        $http_info = curl_getinfo($ch);
        //print_r($http_info);

        if($http_info['http_code'] != 200 && $http_info['http_code'] != 302 ){
            $http_info['error_code'] = curl_errno($ch);
            $http_info['error_info'] = curl_error($ch);

            curl_close($ch);
            return $http_info;
        }

        curl_close($ch);

        return $rs;
    }

    function get_data_from_api(){
        header('Content-type: text/html; charset=UTF-8');
        $rs = $this->send_http('http://test.weibocrawl.com/index.php/weibo_info_api/get_weibos');
        echo '<pre>';
        print_r(json_decode($rs));
    }
}
